<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();
	
	$action = $_GET['action'];
	if($action=='do'){
		$ver = $_POST['ver'];
		$ddata = $_POST['ddata'];
		$dtime = strtotime($_POST['dtime']);
		$cp = $_POST['cp'];
		$dkey = $_POST['dkey'];
		$url = $_POST['url'];
		$qz = $_POST['qz'];
	    $sql="select * from version where ver='$ver' and cp='$cp'";
        $query=mysqli_query($con,$sql);
        $rows = mysqli_num_rows($query); 
		if($rows > 0){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">版本已存在！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'version-add.php' });  }});</script>");
		   die;
		}else{
			$sql = "UPDATE `products` SET `nver` = '$ver',`nkey` = '$dkey',`url` = '$url',`qz` = '$qz',`time` = '$dtime' WHERE `cp` = '$cp';";
			mysqli_query($con,$sql);
		   $sql = "INSERT INTO `version` (`ver`, `ddata`, `dtime`, `dkey`, `cp`, `url`, `qz`) VALUES ('$ver', '$ddata', '$dtime', '$dkey', '$cp', '$url', '$qz');";
	       mysqli_query($con,$sql);
		   mysqli_close();
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">添加成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'version-index.php' });  }});</script>");
		   die;
		}
	}
$li3='class="active"';
$li31='class="active"';
?>
<?php include 'header.php';?>
    <title>添加版本-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>添加版本</h1>
                                <p>填写版本信息并保存.</p>
                            </div>
                        </div>
		   <form action="version-add.php?action=do" method="post"  role="form">
		   
		   <div class="form-group">
                                <label for="txtDomain">产品</label>
                                <select name="cp" class="form-control" >
								
 									<?php 
										$sql="select * from products ORDER BY `id` DESC";
										$result=mysqli_query($con,$sql);
										if($result&&mysqli_num_rows($result)){
											while ($row=mysqli_fetch_assoc($result)) {
											echo "<option value='".$row['cp']."'>".$row['cp']."</option>";											
											}
										}
									?>   
									</select>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">版本号</label>
                                <input type="text" name="ver" class="form-control" value='' autocomplete="off" required/>
                            </div>
							<div class="form-group">
							  <label>是否强制更新</label>
							  <select name="qz" class="form-control">
								<option value="0">否</option>
								<option value="1">是</option>
							  </select>
							</div>
                            <div class="form-group">
                                <label for="txtDomain">更新内容   (请勿使用回车换行，推荐使用< br >)</label>
								<textarea class="form-control" name="ddata" clos="100" rows="5" autocomplete="off" required/><?php echo $ddata?></textarea>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">更新日期</label>
                                <input type="text" name="dtime" class="form-control" id="time1" placeholder="2019-12-12" autocomplete="off" required/>
                            </div>
							<div class="form-group">
                                <label for="txtDomain">下载地址</label>
                                <input type="text" name="url" class="form-control" placeholder="http://开头" autocomplete="off" required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain"><i class="fa fa-key"></i>KEY<input class="btn btn-primary btn-xs" type= "button" name= "Submit1 " value= "生成" onclick= "show()"></label>
                                <input type="text" name="dkey" id="syskey"  class="form-control" value='<?php echo $dkey?>'>
 					<script language=javascript> 
						function show() 
						{ 
						var str= "0123456789abcdefghijklmnopqrstuvwxyz" 
						var result= " " 
						for(var i=0;i <32;i++) 
						{ 
						var temp=Math.floor(Math.random()*36) 
						result+=str.charAt(temp) 
						} 
						hash = result.MD5();
						document.getElementById( "syskey").value=hash
						} 
					</script>
                            </div>

							<input type='hidden' name="id" class="user" value='<?php echo $id?>'/>
			<div id="bottom">
			  <button class="btn btn-info" type="submit" value="true" id="submit"/><strong>提交</strong></button>
            </div>
                        </form>
                    </section>
                    <!--work progress end-->
                </div>

        </section>
    </section>
    <!--main content end-->

<?php include 'footer.php';?>
